import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_app/yaxi/widgets/main.dart';

import '../css/main.dart';
// import '../server/assets.dart';

// import 'event.dart';
import 'page.dart';

void initYaxi() {
  registerWidgets();
  // initEvent();
  // runAssetsServer();
}

class YaxiHost extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return YaxiHostState();
  }
}

class YaxiHostState extends State<YaxiHost> {
  List<dynamic> pageDatas = jsonDecode('[["Page",1]]');

  @override
  Widget build(BuildContext context) {
    List<Widget> children = [];

    var data = jsonDecode('{"Page":1}');

    for (String key in data.keys) {
      String v = key;
    }

    for (dynamic item in pageDatas) {
      var data = CSSNodeData.fromJSONArray(item);

      children.add(Positioned(
          top: 0, left: 0, right: 0, bottom: 0, child: YaxiPage(data)));
    }

    children.add(buildButton(context));

    return Stack(
      children: children,
    );
  }

  Widget buildButton(BuildContext context) {
    return FloatingActionButton(
        child: Text('click me'),
        onPressed: () {
          setState(() {
            pageDatas =
                jsonDecode(pageDatas.length == 0 ? '[["Page",1]]' : '[]');
          });
        });
  }
}
